 package scripting.event;

 import com.fasterxml.jackson.core.type.TypeReference;
 import java.io.File;
 import java.io.IOException;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
 import server.console.groups.boss.BossManagePanel;
 import tools.JsonUtil;


 public class BossEventManager
 {
   private static final String filepath = "./config/boss.json";
   public static boolean ISOPEN = false;
   private static BossEventManager instance;
/*  19 */   private final Map<String, BossEventEntry> bossEntrys = new LinkedHashMap<>();

   public BossEventManager() {
     try {
/*  23 */       if (ISOPEN) {
/*  24 */         load();
       }
/*  26 */     } catch (IOException e) {
/*  27 */       e.printStackTrace();
     }
   }

   public static BossEventManager getInstance() {
/*  32 */     if (instance == null)
/*  33 */       instance = new BossEventManager(); 
/*  34 */     return instance;
   }

   public Set<String> getAllBossName() {
/*  38 */     return this.bossEntrys.keySet();
   }

   public Set<String> getAllBossEventName() {
/*  42 */     Set<String> ret = new LinkedHashSet<>();
/*  43 */     for (BossEventEntry bossEventEntry : this.bossEntrys.values()) {
/*  44 */       ret.add(bossEventEntry.getEventname());
     }
/*  46 */     return ret;
   }

   public boolean canUseDefaultScript(String name) {
/*  50 */     for (BossEventEntry bossEventEntry : this.bossEntrys.values()) {
/*  51 */       if (name.equalsIgnoreCase(bossEventEntry.getEventname()) && bossEventEntry.isUseDefaultScript()) {
/*  52 */         return true;
       }
     }
/*  55 */     return false;
   }

   public BossEventEntry getBossEventEntry(String name) {
/*  59 */     return this.bossEntrys.get(name);
   }

   public void load() throws IOException {
     Map<String, Map<String, String>> bosslist_data;
/*  64 */     File file = new File("./config/boss.json");
/*  65 */     if (!file.exists()) {
/*  66 */       if (!file.mkdirs()) {
/*  67 */         System.out.println("打开BOSS配置文件失败。");
         return;
       }
/*  70 */       bosslist_data = (Map<String, Map<String, String>>)JsonUtil.getMapperInstance().readValue(BossManagePanel.class.getResourceAsStream("bossDefault.json"), new TypeReference<Map<String, Map<String, String>>>() {  }
         );
     } else {
/*  73 */       bosslist_data = (Map<String, Map<String, String>>)JsonUtil.getMapperInstance().readValue(file, new TypeReference<Map<String, Map<String, String>>>() {  }
         );
     }
/*  76 */     if (!bosslist_data.isEmpty()) {
/*  77 */       for (Map.Entry<String, Map<String, String>> entry : bosslist_data.entrySet()) {
/*  78 */         Map<String, String> values = entry.getValue();






/*  85 */         BossEventEntry bossEventEntry = new BossEventEntry(values.get("name"), Boolean.valueOf(values.get("isOpen")).booleanValue(), Boolean.valueOf(values.get("isUseDefaultScript")).booleanValue(), Integer.valueOf(values.get("maxPlayerCount")).intValue(), Integer.valueOf(values.get("maxCount")).intValue(), Integer.valueOf(values.get("maxTime")).intValue());
/*  86 */         this.bossEntrys.put(entry.getKey(), bossEventEntry);
       }
     }
   }

   public class BossEventEntry
   {
     private final String eventname;
     private final boolean isOpen;
     private final boolean isUseDefaultScript;
     private final int maxPlayerCount;
     private final int maxCount;
     private final int maxTime;

     public BossEventEntry(String eventname, boolean isOpen, boolean isUseCustomScript, int maxPlayerCount, int maxCount, int maxTime) {
/* 101 */       this.eventname = eventname;
/* 102 */       this.isOpen = isOpen;
/* 103 */       this.isUseDefaultScript = isUseCustomScript;
/* 104 */       this.maxPlayerCount = maxPlayerCount;
/* 105 */       this.maxCount = maxCount;
/* 106 */       this.maxTime = maxTime;
     }

     public String getEventname() {
/* 110 */       return this.eventname;
     }

     public boolean isOpen() {
/* 114 */       return this.isOpen;
     }

     public boolean isUseDefaultScript() {
/* 118 */       return this.isUseDefaultScript;
     }

     public int getMaxPlayerCount() {
/* 122 */       return this.maxPlayerCount;
     }

     public int getMaxCount() {
/* 126 */       return this.maxCount;
     }

     public int getMaxTime() {
/* 130 */       return this.maxTime;
     }
   }
 }


/* Location:              C:\PGX\Server.jar!\scripting\event\BossEventManager.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */